<%
## -*- mode: R -*-

  if (!is.null(GET$project) ) {
     setCookie(name="strategico.project",value=GET$project)
  }

  strategico.home <- as.character(Sys.getenv("STRATEGICO_HOME"))
  source(file.path(strategico.home, "strategico_util.R"))
  MySource("strategico_web.R")

  page.title <- "status"
  page.sections	<- data.frame()

  if (!is.null(project.name) && !is.null(project.config)) {
     stats <- Project.GetStatisticsDB(project.name, project.config=project.config, db.channel)
     b1 <- paste(capture.output(print(xtable(t(as.data.frame(stats))), type="html")), collapse="\n")
     page.sections <- data.frame(title="Database", body=b1)


     for (value in GetValueNames(project.config$values)) {
  	 stats.models <- Project.GetStatistics.Models(project.name, value, db.channel)
  	 
         if (!is.null(stats.models) && is.data.frame(stats.models) && nrow(stats.models) > 0) {
           M <- gvisPieChart(stats.models, options=list(title=""))
  
           MG <- gvisGauge(stats.models, options=list(title=value, min=0, max=stats[[DB.GetTableNameProjectItems(project.name)]]))
           b_M <- paste(capture.output(cat(M$html$chart)), collapse="\n")
           b_MG <- paste(capture.output(cat(MG$html$chart)), collapse="\n")
	   page.sections <- rbind(page.sections, data.frame(title=paste(value, "models"), body=paste(b_M, b_MG, sep="\n")))
        }
     }
  }

  ##BrewTemplate("page")

  template.file <- file.path(GetWebTemplatesHome(), "page.brew")
  brew(template.file)
%>
